package cn.tedu.supermarket.controller;

import cn.tedu.supermarket.entity.GoodsUser;
import cn.tedu.supermarket.mapper.GoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.io.File;

@Controller
public class DeleteGoodsController {
    @Autowired
    GoodsMapper goodsMapper;

    @RequestMapping("/delete")
    public String deleteGoods(int id, HttpSession session){
        if (session.getAttribute("user")!=null) {
            System.out.println(id);
            GoodsUser goodsUser = goodsMapper.selectById(id);
            System.out.println(goodsUser);

            String path = "/home/soft01"+goodsUser.getImgurl();//需要修改处
            
            File file = new File(path);
            file.delete();
            goodsMapper.deleteGoods(id);
            return "redirect:_del";
        }
        return "redirect:sLoginNow";
    }
}
